import axios, { type AxiosRequestHeaders, type AxiosResponse } from 'axios';
// import NProgress from 'nprogress'
interface ResponseData<T> {
  code: number;
  data: T;
  message: string;
}

// 配置新建一个 axios 实例
const wyAxios = axios.create({
  // baseURL: '/api-dev',
  timeout: 50000,
});

// 添加请求拦截器
wyAxios.interceptors.request.use(
  (config) => {
    // NProgress.start()
    return config;
  }
);

// 添加响应拦截器
wyAxios.interceptors.response.use(

  (response: AxiosResponse<ResponseData<any>, any>) => {
    let res = response.data
    // NProgress.done()
    return res.data
  },
  (error) => {
    // NProgress.done()
    return Promise.reject(error);
  }
);

export default wyAxios;
